package com.glut.forum.controller;

import com.glut.forum.common.beans.ResultBean;
import com.glut.forum.bean.entity.User;
import com.glut.forum.service.IUserService;
import com.glut.forum.service.QnUploadService;
import com.qiniu.common.QiniuException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.List;

/**
 * @author: miloYe
 * @Date: 2021/09/02
 */
@RestController
@RequestMapping("/forum/test")
public class TestController {
    private final IUserService userService;
    private final QnUploadService qnUploadService;

    public TestController(IUserService userService, QnUploadService qnUploadService) {
        this.userService = userService;
        this.qnUploadService = qnUploadService;
    }

    // 这里应该返回上传文件信息
    @GetMapping("/file/upload")
    public String upLoadFile() throws QiniuException {
        File file = new File("/home/milo/Downloads/downloadasdasdasdasdasd.png");
        return qnUploadService.uploadFile(file, "second-img");
    }

    @GetMapping("/aoptest")
    public ResultBean<Boolean> aoptest() {
        return new ResultBean<>(true);
    }

    @GetMapping("/all")
    public ResultBean<List<User>> getAllUsers() {
        return new ResultBean<>(userService.list());
    }
}
